namespace laba2.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class InitialCreate : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.Courses",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false, maxLength: 30),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.Students",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false, maxLength: 30),
                        Address = c.String(maxLength: 50),
                        Email = c.String(maxLength: 20),
                        Phone = c.String(maxLength: 15),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.Achivements",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        TaskId = c.Int(nullable: false),
                        StudentId = c.Int(nullable: false),
                        Rating = c.Int(nullable: false),
                        Date = c.DateTime(nullable: false),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Students", t => t.StudentId, cascadeDelete: true)
                .ForeignKey("dbo.Tasks", t => t.TaskId, cascadeDelete: true)
                .Index(t => t.StudentId)
                .Index(t => t.TaskId);
            
            CreateTable(
                "dbo.Tasks",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        CourseId = c.Int(nullable: false),
                        PassingRating = c.Int(nullable: false),
                        MaximumRating = c.Int(nullable: false),
                        Name = c.String(nullable: false, maxLength: 20),
                        Date = c.DateTime(),
                        PrincipleOfRatingId = c.Int(),
                        Deadline = c.DateTime(),
                        Discriminator = c.String(nullable: false, maxLength: 128),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Courses", t => t.CourseId, cascadeDelete: true)
                .ForeignKey("dbo.PrincipleOfRatingByDates", t => t.PrincipleOfRatingId, cascadeDelete: true)
                .Index(t => t.CourseId)
                .Index(t => t.PrincipleOfRatingId);
            
            CreateTable(
                "dbo.PrincipleOfRatingByDates",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.RatingByDates",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Delay = c.Int(nullable: false),
                        Rating = c.Int(nullable: false),
                        PrincipleOfRatingByDate_Id = c.Int(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.PrincipleOfRatingByDates", t => t.PrincipleOfRatingByDate_Id)
                .Index(t => t.PrincipleOfRatingByDate_Id);
            
            CreateTable(
                "dbo.Evaluations",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        CourseId = c.Int(nullable: false),
                        Minimum = c.Int(nullable: false),
                        Maximum = c.Int(nullable: false),
                        Evaluation1 = c.String(nullable: false, maxLength: 10),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Courses", t => t.CourseId, cascadeDelete: true)
                .Index(t => t.CourseId);
            
        }
        
        public override void Down()
        {
            DropIndex("dbo.Evaluations", new[] { "CourseId" });
            DropIndex("dbo.RatingByDates", new[] { "PrincipleOfRatingByDate_Id" });
            DropIndex("dbo.Tasks", new[] { "PrincipleOfRatingId" });
            DropIndex("dbo.Tasks", new[] { "CourseId" });
            DropIndex("dbo.Achivements", new[] { "TaskId" });
            DropIndex("dbo.Achivements", new[] { "StudentId" });
            DropForeignKey("dbo.Evaluations", "CourseId", "dbo.Courses");
            DropForeignKey("dbo.RatingByDates", "PrincipleOfRatingByDate_Id", "dbo.PrincipleOfRatingByDates");
            DropForeignKey("dbo.Tasks", "PrincipleOfRatingId", "dbo.PrincipleOfRatingByDates");
            DropForeignKey("dbo.Tasks", "CourseId", "dbo.Courses");
            DropForeignKey("dbo.Achivements", "TaskId", "dbo.Tasks");
            DropForeignKey("dbo.Achivements", "StudentId", "dbo.Students");
            DropTable("dbo.Evaluations");
            DropTable("dbo.RatingByDates");
            DropTable("dbo.PrincipleOfRatingByDates");
            DropTable("dbo.Tasks");
            DropTable("dbo.Achivements");
            DropTable("dbo.Students");
            DropTable("dbo.Courses");
        }
    }
}
